import { createStore } from "vuex";
import { ethers } from "ethers";
import createPersistedstate from 'vuex-persistedstate'
import { usdtContract,btcContract } from "../utils/config";
export default createStore({
  state: {
    lendRate:0.8,
    total:{},
    c2cTotal:{},
    myTotal:{},
    fixedTime:[],
    freeTime:[],
    address0:'0x0000000000000000000000000000000000000000',
    latestRecord:{},
    address: "",
    platformFee:0,
    // 最小小费比例
    minFee:0,
    balance: "",
    usdtBalance:"0",
    btcBalance:"0",
    theme: "light",
    // btc价格
    tokenPrice:0,
    cashPledge:0,
    // 申请花费
    applyCost:0,
    tokenName: "USDT",
    USDT:usdtContract[1],
    usdtImg:usdtContract[4], 
    BTC:btcContract[1],
    btcImg:btcContract[4],
    orderItem:{},
    userInfo: {},
    myParent: "",
    userList: [],
    userItem1: {},
    userItem2: {},
    userItem3: {},
    orderList: [],
    // c2c
    orderList2:[],
    isAdmin: false,
    allOrder: [],
    allUser: [],
    collectShop:[],
    collectUser:[],
    myUserObj:{},
    myShop:{},
    shopList:[],
    unCheckedShop:[],
    outShop:[],

  },
  getters: {},
  mutations: {
    changeC2CTotal(state,payload ){
      state.c2cTotal = payload;
    },
    changeFixedTime(state,payload ){
      state.fixedTime = payload;
    },
    changeLatestRecord(state,payload ){
      state.latestRecord = payload;
    },
    
    changeFreeTime(state,payload ){
      state.freeTime = payload;
    },
    changeCashPledge(state,payload ){
      state.cashPledge = payload;
    },
    changeMyTotal(state,payload ){
      state.myTotal = payload;
    },
    changeTotal(state,payload ){
      state.total = payload;
    },
    changePlatformFee(state,payload ){
      state.platformFee = payload;
    },
    changeMinFee(state,payload ){
      state.minFee = payload;
    },
    
    changeLendRate(state,payload ){
      state.lendRate = payload;
    },
    changeTokenPrice(state,payload ){
      state.tokenPrice = payload;
    },
    changeUsdtBalance(state, payload) {
      state.usdtBalance = payload;
    },
    changeBtcBalance(state, payload) {
      state.btcBalance = payload;
    },
    changeApplyCost(state, payload) {
      state.applyCost = payload;
    },
    changeShopList(state, payload) {
      state.shopList = payload;
    },
    changeUnCheckedShop(state, payload) {
      state.unCheckedShop = payload;
    },
    changeOutShop(state, payload) {
      state.outShop = payload;
    },
    changeTokenName(state, payload) {
      state.tokenName = payload;
    },
    changeUserInfo(state, payload) {
      state.userInfo = payload;
    },
    changeMyParent(state, payload) {
      state.myParent = payload;
    },
    changeAdmin(state, payload) {
      state.isAdmin = payload;
    },
    addTheme(state, payload) {
      state.theme = payload;
    },
    changeAddress(state, payload) {
      state.address = payload;
    },
    changeOrderList(state, payload) {
      state.orderList = payload;
    },
    changeOrderList2(state, payload) {
      state.orderList2 = payload;
    },
    changeUserList(state, payload) {
      state.userList = payload;
    },
    changeAllOrder(state, payload) {
      state.allOrder = payload;
    },
    changeAllUser(state, payload) {
      state.allUser = payload;
    },
    changeShopList(state, payload) {
      state.shopList = payload;
    },
    BALANCE(state, payload) {
      state.balance = payload;
    },
    chooseUser1(state, payload) {
      state.userItem1 = payload;
    },
    chooseUser2(state, payload) {
      state.userItem2 = payload;
    },
    changeOrderItem(state, payload) {
      state.orderItem = payload;
    },
    chooseUser3(state, payload) {
      state.userItem3 = payload;
    },
    changeCollectShop(state, payload) {
      state.collectShop = payload;
    },
    changeCollectUser(state, payload) {
      state.collectUser = payload;
    },
    changeMyUserObj(state, payload) {
      state.myUserObj = payload;
    },
    changeMyShop(state, payload) {
      state.myShop = payload;
    },
  },
  actions: {},
  plugins: [
    // 持久化插件
    createPersistedstate({
      storage: window.localStorage,
      reducer(val) {
        return {
          total:val.total,
          address: val.address,
          userList: val.userList,
          userItem: val.userItem,
          tokenName: val.tokenName,
          collectShop: val.collectShop,
          collectUser:val.collectUser,
          fixedTime:val.fixedTime,
          freeTime:val.freeTime,
          shopList:val.shopList,
          myUserObj:val.myUserObj,
          orderList2:val.orderList2,
          latestRecord:val.latestRecord
        };
      },
    }),


  ],
  modules: {},
});